import { strictEqual } from 'assert';
import { Mock } from 'lite-ts-mock';
import { TreePSD } from 'psd';

import { ConverterBase } from './base';
import { Sprite, Toggle } from './cc';
import { ToggleConverter as Self } from './toggle';
import { ConverterFactoryBase } from '../../contract';

describe('src/scene/service/converter/toggle.ts', () => {
    describe('.convert()', () => {
        it('ok', async () => {
            const mockConverterFactory = new Mock<ConverterFactoryBase>();
            const mockTreePSD = new Mock<TreePSD>();
            const self = new Self(null as any, mockConverterFactory.actual, null as any, mockTreePSD.actual);

            const node = {
                children: [{
                    getComponent: (arg: any) => {
                        strictEqual(arg, 'a');
                        return 'b';
                    }
                }]
            };
            Reflect.set(self, 'createNode', () => {
                return node;
            });

            Reflect.set(self, 'addChildren', (arg: any) => {
                strictEqual(arg, node);
            });

            const toggle = {
                checkMark: null
            };
            Reflect.set(self, 'appendComponent', (arg: any, arg1: any) => {
                strictEqual(arg, Toggle);
                strictEqual(arg1, node);
                return toggle;
            });

            ConverterBase.getCcPropFunc = (arg: any) => {
                strictEqual(arg, Sprite.name);
                return 'a';
            };

            const res = await self.convert();
            strictEqual(res, node);
            strictEqual(toggle.checkMark, 'b');
        });
    });
});